import app, { xlsxCfgNames } from "../../../../app"
import { face_Points, face_attributes } from "../../../../shared/interface"
import { _Cls_Att } from "./_Att"


export class _Cls_Points implements face_Points, face_attributes {
    /**
     * 力量 最大生命 物理攻击
     */
    a: number = 0
    /**
     * 敏捷 普通攻击次数
     */
    c: number = 0
    /**
     * 精神 法术强度  精神力
     */
    b: number = 0
    /**
     * 幸运 宠物数量 法术暴击率
     */
    d: number = 0;
    // 白盾
    _wall_hp: number = 0;
    /**
     * 额外增加最大生命值
     */
    Hp_Max: number = 0;
    Hp_res: number = 0;
    Mp_Max: number = 0;
    Mp_res: number = 0;
    Physical_Attack_max: number = 0;
    Physical_Attack_min: number = 0;
    Physical_Ls: number = 0;
    Physical_crit: number = 0;
    Physical_defense: number = 0;
    Magic_Attack_max: number = 0;
    Magic_Ls: number = 0;
    Magic_defense: number = 0;
    Magic_crit: number = 0;
    Magic_Attack_min: number = 0;
    Attack_Speed: number = 0;
    Calls_cont: number = 0;
    Calls_leveMax: number = 0;
    Calls_leveMin: number = 0;
    Calls_sore: number = 0;
    private _att = new _Cls_Att();
    constructor(data?: any) {
        if (data) {
            this.reset(data);
        }
    }
    dbsave(){
        let obj:any = {}
        for (const key in this) {
            if(key.startsWith('_')){
                continue;
            }
            if(typeof(this[key]) == 'number' && !this[key]){
                continue;
            }
            obj[key] = this[key];
        }
        return obj
    }
    random(score: number) {
        let total = Math.ceil(score);
        let arry = ['a', 'b', 'c', 'd']
        app.shuffleArray(arry)
        const attCfg = app.xlsxCfgMap.get(xlsxCfgNames.属性配置) as Map<string, any>
        for (let i = 0; i < arry.length; i++) {
            const key = arry[i];
            if (typeof (this[key]) != 'number') {
                continue;
            }
            const cfg = attCfg.get(key)
            /**
             * 属性价值
             */
            const value = cfg.value;
            total = this.random_key(key, value, total);
            if (total == 0) {
                break;
            }
        }

    }
    private random_key(key: string, power: number, score: number) {
        if (score < 1) {
            this[key] = 0;
            return 0
        }
        let randomVal = app.generateRandom(1, score, score)
        let supVal = score - randomVal;
        this[key] = randomVal * power;
        return supVal;
    }
    resetAtt() {
        let cover = app.contPToAtt(this, this._att);
        this._att.reset(cover)
    }

    getMultiple(num: number) {
        let p = new _Cls_Points();
        for (const key in p) {
            if (typeof (p[key]) != 'number') {
                continue;
            }
            p[key] = num * this[key];
            if (isNaN(p[key])) {
                debugger;
            }
        }
        return p;
    }
    Multiple(cfg: any, num: number) {
        for (const key in cfg) {
            if (typeof (cfg[key]) != 'number') {
                continue;
            }
            this[key] += num * cfg[key];
        }
        return this;
    }
    /**
     * 转为二级属性
     */
    cover2Att() {
        this.resetAtt()
        return this._att;
    }
    clearAll() {
        let z: any = 0;
        for (const key in this) {
            if (typeof (this[key]) == 'number') {
                this[key] = z;
            }
        }
    }
    reset(data: any) {
        if (!data) {
            return;
        }
        for (const key in data) {
            if (key == '_att') {
                continue;
            }
            if (typeof (this[key]) == 'number') {
                this[key] = data[key]
            }
        }
    }
    add(data: any) {
        for (const key in data) {
            if (typeof (this[key]) == 'number') {
                this[key] += data[key]
            }
        }
    }
}